class MyStack:
    """
    栈的简单实现
    """

    def __init__(self, data=None):
        """
        :param data: list
        """
        if data is None:
            self.data = []
            self._size = 0
            return

        self.data = data
        self._size = len(data)

    def is_empty(self):
        return self._size == 0

    def push(self, value):
        self.data.append(value)
        self._size += 1

    def pop(self):
        if self._size > 0:
            self._size -= 1
            return self.data.pop()

    def peek(self):
        return self.data[self._size - 1]

    def size(self):
        return len(self.data)

    def __repr__(self):
        return "{}:{}".format(self._size, str(self.data))


st = MyStack()
st.push(1)
st.push(2)
st.push(3)
print(st)
st.pop()
print(st)
st.pop()
print(st.peek())
st.pop()
print(st.is_empty())
st.pop()
st.pop()

# reverse a word

word = "congratulation"
st = MyStack(list(word))
reversed_word = ""

for i in range(st.size()):
    reversed_word += st.pop()
print(reversed_word)
